
package htmlparse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HtmlParse {

    public static void main(String[] args) throws IOException {
        long begin = System.currentTimeMillis();
        int m = 40, n = 50;
        int[][] a = new int[m][n];
        int r = (int) (m+n-2)/4;//Math.floor();
        int k = 0;
        int b = 0;//每圈起点
        int t = 0;
        int j;
        for (int i = 0; i <= r; i++) {
            int s = 2*(m+n)-8*i-4;//每圈个数
            int row = m - 2*i;//行偏移
            int clo = n - 2*i;//列偏移
            //System.out.println("col:"+clo+"  row:"+row);
            
            //System.out.println("每圈第一横");
            //System.out.println("k="+k);
            j = i;
            if (k>m*n-1) {
                break;
            }
            while(b <= k && k < b + clo) {
                //System.out.println("j:"+j+"  k:"+k);
                a[i][j] = k;
                k++;
                //System.out.println("a["+i+"]["+j+"]="+a[i][j]);
                j++;
            } 
            
            //每圈第二竖
            k--;
            j = i;
            //System.out.println("k2:"+k);
            t = k;
            if (k>m*n-1) {
                break;
            }
            while(t <= k && k < t+row) {
                //System.out.println("j:"+j+"  k:"+k);
                a[j][n-1-i] = k;
                //System.out.println("a["+j+"]["+(n-1-i)+"]="+a[j][n-1-i]);
                k++;
                j++;
            }
            
            //每圈第三横
            k--;
            j = n-i-1;
            int tj = n-2*i-1;
            t = k;
            //System.out.println("k3:"+k);
            //System.out.println("j3:"+j);
            if (k>m*n-1) {
                break;
            }
            while(t <= k && k< t+tj+1){
                a[m-1-i][j] = k;
                //System.out.println("a["+(m-1-i)+"]["+(j)+"]="+a[m-1-i][j]);
                k++;
                j--;
            }
            
            //每圈第四竖
            k--;
            j = m-1-i;
            tj = m-1-2*i;
            t = k;
            //System.out.println("k4:"+k);
            //System.out.println("j4:"+j);
            if (k>m*n-1) {
                break;
            }
            while (t <= k && k < t+tj) {
                a[j][i] = k;
                k++;
                //System.out.println("a["+j+"]["+i+"]="+a[j][i]);
                j--;
            }
            b = s + b;
            //System.out.println("b:"+b);
        }
        long end = System.currentTimeMillis();
        System.out.println("total time:"+(end-begin)+"ms");
        for (int i = 0; i < m; i++) {
            for (int p = 0; p < n; p++) {
                System.out.print(a[i][p] + "  ");
            }
            System.out.println();
        }

        Student s = new Student();
        s.setAge(19);
        change(s);
        System.out.println(s.getAge());

    }
    
    static void change(Student ss) {
        ss.setAge(10);
    }
    
    public static String getHTML(String pageURL, String encoding) {
        StringBuilder pageHTML = new StringBuilder();
        try {
            URL url = new URL(pageURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0");
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));
            String line = null;
            while ((line = br.readLine()) != null) {
                pageHTML.append(line);
                pageHTML.append("\r\n");
            }
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageHTML.toString();
    }
}
